package com.military.mapper;

import com.github.pagehelper.Page;
import com.military.pojo.MilitaryQueryParam;
import com.military.pojo.MilitaryStandard;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Mapper
public interface MilitaryStandardMapper {

//    /**
//     * 查询所有的军标数据
//     * @return
//     */
//    @Select("SELECT id,file_type,`name`,description,tag,upload_time FROM military ORDER BY upload_time DESC")
//    List<MilitaryStandard> findAll();

//
//    /**
//     * 查询总记录数
//     * @return
//     */
//    @Select("select count(*) from military ")
//    public Long count();
//
//    /**
//     * 分页查询
//     * @param start
//     * @param pageSize
//     * @return
//     */
//    @Select("select * from military order by upload_time desc limit #{start},#{pageSize}")
//    public List<MilitaryStandard> list(Integer start, Integer pageSize);

    /**
     * 分页查询
     *
     *
     */
    @Select("select * from military order by upload_time desc")
    public List<MilitaryStandard> list();


    /**
     * 根据条件查询数据
     * @param
     * @param
     * @return
     */
    //@Select("select id, file_type, name, description, tag, upload_time from military where file_type like '%${fileType}%' and name like '%${name}%'")
    List<MilitaryStandard> pageId(MilitaryQueryParam queryParam);


    /**
     * 根据id删除数据
     * @param id
     */
    @Delete("delete from military where id = #{id}")
    void deleteId(Integer id);

    /**
     * 新增军标数据
     * @param militaryStandard
     */
    @Insert("insert into military(file_type, name, description, tag, upload_time) VALUES (#{fileType},#{name},#{description},#{tag},#{uploadTime})")
    void add(MilitaryStandard militaryStandard);

    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    @Select("select id, file_type, name, description, tag, upload_time from military where id=#{id}")
    MilitaryStandard getInfo(Integer id);

    /**
     * 修改军标数据
     * @param militaryStandard
     */
    @Update("update military set file_type = #{fileType},name = #{name},description = #{description},tag = #{tag} where id = #{id}")
    void update(MilitaryStandard militaryStandard);

    /**
     * 统计军标数据
     * @return
     */
    List<Map<String ,Object>> countMilitaryData();

}
